#include <stdio.h>
#include <stdlib.h>
#define QueueSize 5
typedef char DataType;
typedef struct {
    DataType data[QueueSize];
    int front, rear;
} CirQueue;

//置空
void InitQueue(CirQueue *Q) {
    Q->front = Q->rear = 0;
}

int QueueEmpty(CirQueue *Q)
{
    return Q->rear == Q->front;
}

//
int QueueFull(CirQueue *Q) {
    return (Q->rear + 1) % QueueSize == Q->front;
}

//
void EnQueue(CirQueue *Q, DataType x)
{
    if(QueueFull(Q)){
        printf("overflow");
    }else{
        Q->data[Q->rear] = x;
        Q->rear = (Q->rear+1) % QueueSize;//循环意义下加 1
    }
}

DataType DeQueue(CirQueue *Q)
{
    DataType x;
    if(QueueEmpty(Q)){
        printf("underflow");
        exit(0);
    }
    x = Q->data[Q->front];
    Q->front = (Q->front + 1) % QueueSize;
    return x;
}

DataType GetTop(CirQueue *Q)
{
    if (QueueEmpty(Q))
    {
        printf("underflower");
    }
    else
    {
        return Q->data[Q->front];
    }
}

void DeAllQueue(CirQueue *Q)
{
    while(!QueueEmpty(Q)){
        putchar(Q->data[Q->front]);
        Q->front = (Q->front + 1) % QueueSize;
    }
}

int main()
{
    CirQueue Q;
    InitQueue(&Q);
    EnQueue(&Q, 'a');
    EnQueue(&Q, 'b');
    EnQueue(&Q, 'c');
    EnQueue(&Q, 'd');
    DeAllQueue(&Q);
    printf("%d", QueueEmpty(&Q));
//    EnQueue(&Q, 'e');
    return 0;
}